<!-- 移动签批->公文详情->收文->收文详情 -->
<!-- 收文管理->收文详情 -->
<template>
  <view>
    <van-tabs color="#1989fa" title-active-color="#1989fa" animated swipeable @change="onChange">
      <van-tab title="公文详情" name="gwxq">
        <detail ref="detail" :detailObj1="detailObj1" :proInstId="proInstId" @showFenfaSheet="showFenfaSheet"></detail>
      </van-tab>
      <van-tab title="版式稿纸" name="bsgz">
        <read :detailObj1="detailObj1" :proInstId="proInstId"></read>
      </van-tab>
      <van-tab title="流转过程" name="lzgc" :key='2'>
        <docProcess :dataList="dataList"></docProcess>
      </van-tab>
    </van-tabs>
    <edit ref="edit" @refreshBtnGroup="refreshBtnGroup" :showEdit="showEdit" :detailObj="detailObj1.detailObj"
          @closeEdit="closeEdit"></edit>
    <records @refreshBtnGroup="refreshBtnGroup" :showRecords="showRecords" @closeRecords="closeRecords"
             :paramObject="paramObject"></records>
    <trans ref="trans" :proInstId="proInstId" @refreshBtnGroup="refreshBtnGroup" :showTrans="showTrans"
           @closeTrans="closeTrans" :paramObject="paramObject" :detailObject="detailObj1.detailObj" :fromType="fromType"></trans>
    <distribute ref="distribute" @refreshBtnGroup="refreshBtnGroup" :showDistribute="showDistribute"
                @closeDistribute="closeDistribute" :paramObject="paramObject"
                :detailObject="detailObj1.detailObj"></distribute>
    <send ref="send" @refreshBtnGroup="refreshBtnGroup" :showSend="showSend" @closeSend="closeSend"
          :paramObject="paramObject" :detailObject="detailObj1.detailObj" :nextActivity="fsActivity"></send>
    <more :showShare="showShare" @closeShare="closeShare" :options="barList.slice(4)"></more>
    <fenfa ref="fenfa" :showFenfa="showFenfa" @closeFenfaSheet="closeFenfaSheet"></fenfa>
    <div style="height: 5rem;" v-if="fromType != 'search'">
      <van-tabbar v-model="active">
        <van-tabbar-item v-for="(item,index) in barList" :key="index" v-if="index < 4" :name="item.name"
                         @click="onClick(item.operation)">
          <span>{{ item.value }}</span>
          <template #icon="props">
            <img :src="props.active ? item.iconTab.active : item.iconTab.inactive"/>
          </template>
        </van-tabbar-item>
      </van-tabbar>
    </div>
  </view>
</template>

<script>
import detail from 'pages/jgj/components/receiveDoc/compo-detail';
import docProcess from 'pages/jgj/components/receiveDoc/compo-process';
import read from 'pages/jgj/components/receiveDoc/compo-read';
import records from 'pages/jgj/components/common/compo-records';
import trans from 'pages/jgj/components/receiveDoc/compo-trans';
import distribute from 'pages/jgj/components/receiveDoc/compo-distribute';
import edit from 'pages/jgj/components/receiveDoc/compo-edit';
import send from 'pages/jgj/components/receiveDoc/compo-send';
import more from 'pages/jgj/components/receiveDoc/compo-more';
import fenfa from 'pages/jgj/components/common/compo-fenfa';
export default {
  components: {
    detail,
    docProcess,
    records,
    trans,
    distribute,
    more,
    edit,
    send,
    read,
    fenfa
  },
  onLoad: async function (option) {
    await this.$onLaunched //解決bug：执行完onLaunch后再执行页面onLoad
    // 从缓存获取用户信息
    this.userInfo = this.cache.get('userInfo')
    this.fromType = option.from
    // 从地址栏获取proInstId
    this.proInstId = option.proInstId
    if (this.proInstId != undefined && this.proInstId != '') {
      // 通过proInstId获取详情
      this.getCaacDetail(this.proInstId)
      this.getCaacOpinion(this.proInstId) // 获取意见
    }
  },
  created() {

  },
  //文件编辑保存后返回到首页就重新获取文件及附件
  onShow(){
    //延迟调用，防止文件过大PC端没保存上就获取
    setTimeout(() => {
      if(this.util.isNotEmpty(this.relateId)){
        this.getCaacBody(this.relateId)//获取正文
        this.getCaacAttachment(this.relateId)//获取附件
        this.getRelation(this.relateId)//获取附加公文
      }
    }, 800)
  },
  data() {
    return {
      // 记录对应的tab页数据是否已加载
      gwxqFlag: true,
      bsgzFlag: true,
      lzgcFlag: true,
      relateId: '',
      proInstId: '',
      fromType: '',
      swId: '',				// 收文id
      gwSercet: {},		// 公文秘书，调退公文秘书接口用参数
      gwSercetCs: {},		// 处室秘书，调退公文秘书接口用参数
      userInfo: {},		// 当前登录用户信息，目前先从缓存中获取
      tuiCs: [],	// 退处室秘书所需参数，调用listNextActivities接口获得
      tuiGongWen: [],	// 退公文秘书所需参数，调用listNextActivities接口获得
      endGongWen: [],	// 结束公文所需参数，调用listNextActivities接口获得
      fsActivity: [],  // 分送管理所需参数，调用listNextActivities接口获得
      active: '',
      showEdit: false,      // 修改公文要素
      showRecords: false,   // 填写意见
      showTrans: false,     // 流转
      showDistribute: false,// 批示分送
      showSend: false,      // 分送管理
      showShare: false,     // 更多
      barList: [],          // 功能按钮
      // 公文详情
      detailObj1: {
        detailObj: null,       // 详情
        detailBody: null,      // 正文
        detailAttachment: null,// 附件
        relation: null,        // 附加公文
        opinion: null,         // 意见
        optionBtn01: null,     // 获取签批功能菜单所需要的参数
        optionBtn02: null,     // 获取签批功能菜单所需要的参数
        optionBtn: null,       // 签批功能菜单,根据optionBtn01和optionBtn02返回的参数作为请求参数
      },
      dataList: {
        docProcess: {}, // 流转过程
        signProcess: [],// 会签件
      },
      options: [],      // 更多操作
      paramObject: {},  // 获取签批功能的接口里有
      buttonArr: [],    // 要显示的功能按钮
      showFenfa: false,//分发组件
    };
  },

  mounted() {
    //处理页面弹出层初始化
    this.active = 'gwxq'
    this.showEdit = false
    this.showRecords = false
    this.showTrans = false
    this.showShare = false
    this.showDistribute = false
    this.showGenerate = false

    // 延迟调用listNextActivities获取下一活动节点信息，
    setTimeout(() => {
      this.listNextActivities()
    }, 2000)
  },

  methods: {
    //显示分发组件
    showFenfaSheet(){
      this.showFenfa = true
    },
    //关闭分发组件
    closeFenfaSheet(userInfo){
      //userInfo: {"userId":["2163","8943"],"userName":["刘xx","刘xx"]}
      this.$refs.detail.initParam(userInfo)
      this.showFenfa = false
    },
    // tab 点击事件
    onChange(itemTitle) {
      // 公文详情
      if (itemTitle == 'gwxq') {
        if (this.gwxqFlag) {
          this.getCaacDetail(this.proInstId)
        }
      } else if (itemTitle == 'bsgz') {
        // 版式稿纸
        if (this.bsgzFlag) {
          //TODO 加载版式稿纸
        }
      } else if (itemTitle == 'lzgc') {
        // 流转过程
        if (this.lzgcFlag) {
          this.getCaacDocProcess(this.proInstId)
          this.getListChildSubOperationLogs(this.proInstId)
        }
      }
    },
    // 关闭修改公文要素
    closeEdit(showEdit) {
      this.showEdit = false
    },
    // 关闭填写意见
    closeRecords(showRecords) {
      this.showRecords = false
    },
    // 关闭流转
    closeTrans(showTrans) {
      this.showTrans = false
    },
    // 关闭更多操作
    closeShare(item) {
      this.showShare = false
      this.btnFunction(item)
    },
    // 关闭批示分发
    closeDistribute(item) {
      this.showDistribute = false
    },
    // 关闭分送配置
    closeSend(item) {
      this.showSend = false
    },
    // 点击tabbar
    onClick(item) {
      this.btnFunction(item)
    },
    // 下边菜单点击功能
    btnFunction(item) {
      // 填写意见
      if (item == 'addReviews') {
        this.showRecords = true
      }
      // 填写收文要素
      if (item == 'swys') {
        this.showEdit = true
      }
      // 分送管理
      if (item == 'fensongManagement') {
        this.showSend = true
      }
      // 已阅
      if (item == 'readalready') {
        this.readGwDialog()
      }
      // 已阅
      if (item == 'jmsyy') {
        this.readGwDialog()
      }
      // 批示分送
      if (item == 'psfs') {
        this.showDistribute = true
      }
      // 更多操作
      if (item == 'more') {
        this.showShare = true
      }
      // 退公文秘书
      if (item == 'tgwms' || item == 'tuichushiMs') {
        this.tuiGwmsConfirm(item)
      }
      // 退收文人员
      if (item == 'tuihui') {
        this.tuiSwry()
      }
      // 结束公文
      if (item == 'endProcess') {
        this.endProcess()
      }
      // 流转
      if (item == 'complete') {
        this.showTrans = true
      }
      // 删除
      if (item == 'delForm') {
        this.deleteDoc()
      }
      // 撤回，收文办理-所有收文状态为待审核的文有该功能
      if (item == 'chehui') {
        this.chehuiConfirm()
      }
    },

    //获取要显示的按钮
    async getButtonsData(proInstId) {
      // proInstId = 'c96d8fbcc1f000011ac1cea035606e10'
      const _this = this
      await this.$http({
        url: this.$http.adornUrl(`/caac/oa/app/getButtonsData`),
        method: 'get',
        params: this.$http.adornParams({
          // 'extendIdForRelate': this.proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'proInstId': proInstId
        })
      }).then(({data}) => {
        if (data.code == 200) {
          this.buttonArr = data.data.buttons
          console.log('显示的button--->' + JSON.stringify(this.buttonArr));
        }
      })
    },

    // 获取收文详情数据
    getCaacDetail(proInstId) {
      var _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/authority/sw/proInstId/` + proInstId),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        console.log("------公文详情-sw: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.detailObj1.detailObj = data.data
          _this.swId = data.data.swId
          _this.relateId = data.data.relateId
          _this.getCaacBody(_this.relateId)       // 获取正文
          _this.getCaacAttachment(_this.relateId) // 获取附件
          _this.getRelation(_this.relateId)       // 获取附加公文
          _this.openwfneededdata(_this.swId, proInstId)

          this.gwxqFlag = false // 请求成功后置为false，防止tab切换重新获取数据
        }

      })
    },

    // 获取正文数据
    getCaacBody(relateId) {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/attachmentupload/attachmentinfoOrderBy`),
        method: 'get',
        params: this.$http.adornParams({
          'bizId': relateId,
          'attachTypeId': 'pageBody_mainText',
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.detailObj1.detailBody = data.data
        }
        console.log("------正文-maintext: " + JSON.stringify(_this.detailObj1.detailBody));
      })
    },

    // 获取附件数据
    getCaacAttachment(relateId) {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/attachmentupload/attachmentinfoOrderBy`),
        method: 'get',
        params: this.$http.adornParams({
          'bizId': relateId,
          'attachTypeId': 'pageBody_uploadFile',
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          _this.detailObj1.detailAttachment = data.data
        }
        console.log("------附件-attachmentinfoOrderBy: " + JSON.stringify(_this.detailObj1.detailAttachment));
      })
    },

    // 获取意见
    getCaacOpinion(proInstId) {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/component/approval/approvalwrite`),
        method: 'get',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          if (data.data != null) {
            _this.detailObj1.opinion = data.data
          }
        }
        console.log("------意见-approvalwrite: " + JSON.stringify(data));
      })
    },

    // 获取附加公文
    getRelation(relateId) {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/mhjComponent/relationfile/relation`),
        method: 'get',
        params: this.$http.adornParams({
          'docId': relateId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          if (data.data != null) {
            _this.detailObj1.relation = data.data
          }
        }
        console.log("------附加公文-relation: " + JSON.stringify(data));
      })
    },

    // 获取流转过程
    getCaacDocProcess(proInstId) {
      var _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/workflow/workflowController/listProInstIdOperationLogs`),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        console.log("------流转过程-listProInstIdOperationLogs: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.dataList.docProcess = data.data
          this.lzgcFlag = false
        }

      })
    },
    // 获取子流转过程
    getListChildSubOperationLogs(proInstId) {
      var _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/workflow/workflowController/listChildSubOperationLogs`),
        method: 'post',
        params: this.$http.adornParams({
          'proInstId': proInstId,
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag//固定值
        })
      }).then(({data}) => {
        console.log("------子流转过程-listChildSubOperationLogs: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.dataList.signProcess = data.data
        }

      })
    },

    // 获取签批功能菜单optionBtn01
    openwfneededdata(swId, proInstId) {
      let actUrl = ''
      if (this.fromType != 'db') {
        actUrl = '/caac/oa/comm/comm/openwfswneededdata';
      } else {
        actUrl = '/caac/oa/comm/comm/openwfneededdata'
      }
      this.$http({
        url: this.$http.adornUrl(actUrl),
        method: 'get',
        params: this.$http.adornParams({
          'id': swId,             // 详情返回的swId
          'proInstId': proInstId, // 详情返回的proInstId
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag
        })
      }).then(({data}) => {
        if (data.code == 200) {
          this.detailObj1.optionBtn01 = data.data
          this.paramObject = data.data
          console.log("------签批功能菜单-openwfswneededdata: " + JSON.stringify(data.data));
          this.getRoleTypesAndActInst(data.data.configId, proInstId)
        }

      })
    },

    // 获取签批功能菜单optionBtn02
    getRoleTypesAndActInst(configId, proInstId) {
      var _this = this
      let actUrl = ''
      let paramsData = {
        'proInstId': proInstId, // 发文详情返回的proInstId
        'configId': configId,   // openwfswneededdata()返回的configId
        'systemKey': this.userInfo.systemKey,//固定值
        'systemFlag': this.userInfo.systemFlag//固定值
      }
      if (this.fromType == 'db') {
        actUrl = '/caac/wfm/ApplicationController/getRoleTypesAndActInst';
      } else {
        actUrl = '/caac/wfm/ApplicationController/getRoleTypesAndActInstBeforeSubflow'
        this.$set(paramsData, 'actInstId', this.paramObject.actInstId)
        this.$set(paramsData, 'userId', this.detailObj1.detailObj.createUserId)
      }
      this.$http({
        url: this.$http.adornUrl(actUrl),
        method: 'post',
        params: this.$http.adornParams(paramsData)
      }).then(({data}) => {
        if (data.code == 200) {
          _this.detailObj1.optionBtn02 = data.data
          console.log("------签批功能菜单2-getRoleTypesAndActInst: " + JSON.stringify(data.data));
          _this.initActivity()
        }
      });
    },

    /**
     * 子页面流转后调用此方法刷新功能按钮
     * @param {Object} item Boolean值，为true 就刷新
     */
    refreshBtnGroup(item) {
      this.getCaacDetail(this.proInstId)
      this.getCaacOpinion(this.proInstId)
      // 延迟调用listNextActivities获取下一活动节点信息，
      setTimeout(() => {
        this.listNextActivities()
      }, 2000)
    },
    // 获取功能菜单
    async initActivity() {
      // 获取要显示的按钮
      await this.getButtonsData(this.proInstId)
      const _this = this
      let option01 = this.detailObj1.optionBtn01
      let option02 = this.detailObj1.optionBtn02.actInstList[0] //TODO 次处返回了数组格式，需和pc端确认
      await this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/initActivity`),
        method: 'post',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,
          'systemFlag': this.userInfo.systemFlag,
          'data': this.$http.adornData({
            'configId': option01.configId, // openwfswneededdata()返回的configId
            'configCode': option01.configCode,
            'proDirId': option01.proDirId,
            'actDefId': option01.actDefId,
            'wfmRoleTypes': option02.wfmRoleTypes,
            'proInstId': option01.proInstId,
            'actInstId': option01.actInstId,
            'workitemId': option01.workitemId,
            'wfmInitPageType': 'running',
            'bizId': option01.bizId
          }),

        })
      }).then(({data}) => {
        console.log("------功能菜单-initActivity: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.detailObj1.optionBtn = data.data
          var operations = data.data.qualifiedOperations
          _this.barList = [] // 重置为空
          if (operations != null && operations.length > 0) {
            //TODO 还需判断其他类型的按钮
            for (let i = 0; i < operations.length; i++) {
              // 填写意见
              if (operations[i].operation == 'addReviews') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'addReviews',
                  // 供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  icon: 'static/imgs/icon/icon-opinion.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-opinion-active.png',
                    inactive: 'static/imgs/icon/icon-opinion.png'
                  },
                  value: operations[i].operationName,
                  sort: 1
                })
              }
              // 填写收文要素
              if (operations[i].operation == 'swys') {
                _this.barList.push({
                  name: '修改收文要素',
                  operation: 'swys',
                  // 供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  icon: 'static/imgs/icon/icon-xggwys.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-xggwys-active.png',
                    inactive: 'static/imgs/icon/icon-xggwys.png'
                  },
                  value: '修改收文要素',
                  sort: 7
                })
              }
              // 分送管理
              if (operations[i].operation == 'fensongManagement') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'fensongManagement',
                  // 供更多操作里的按钮使用，因其icon不能自定义，故给其单独的icon地址
                  icon: 'static/imgs/icon/icon-finishsend.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-finishsend-active.png',
                    inactive: 'static/imgs/icon/icon-finishsend.png'
                  },
                  value: operations[i].operationName,
                  sort: 4
                })
              }
              // 已阅
              if (operations[i].operation == 'readalready') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'readalready',
                  icon: 'static/imgs/icon/icon-agree.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-agree-active.png',
                    inactive: 'static/imgs/icon/icon-agree.png'
                  },
                  value: operations[i].operationName,
                  sort: 3
                })
              }
              // 已阅
              if (operations[i].operation == 'jmsyy') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'jmsyy',
                  icon: 'static/imgs/icon/icon-agree.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-agree-active.png',
                    inactive: 'static/imgs/icon/icon-agree.png'
                  },
                  value: operations[i].operationName,
                  sort: 3
                })
              }
              // 退公文秘书
              if (operations[i].operation == 'tgwms' || operations[i].operation == 'tuichushiMs') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: operations[i].operation,
                  icon: 'static/imgs/icon/icon-tuigwms.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-tuigwms-active.png',
                    inactive: 'static/imgs/icon/icon-tuigwms.png'
                  },
                  value: operations[i].operationName,
                  sort: 2
                })
              }
              // 批示分送
              if (operations[i].operation == 'psfs') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'psfs',
                  icon: 'static/imgs/icon/icon-handover.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-handover-active.png',
                    inactive: 'static/imgs/icon/icon-handover.png'
                  },
                  value: operations[i].operationName,
                  sort: 4
                })
              }
              // 流转
              if (operations[i].operation == 'complete') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'complete',
                  icon: 'static/imgs/icon/icon-transfer.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-transfer-active.png',
                    inactive: 'static/imgs/icon/icon-transfer.png'
                  },
                  value: operations[i].operationName,
                  sort: 5
                })
              }
              // 退收文人员
              if (operations[i].operation == 'tuihui') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'tuihui',
                  icon: 'static/imgs/icon/icon-tuigwms.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-tuigwms-active.png',
                    inactive: 'static/imgs/icon/icon-tuigwms.png'
                  },
                  value: operations[i].operationName,
                  sort: 6
                })
              }
              // 结束公文
              if (operations[i].operation == 'endProcess') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'endProcess',
                  icon: 'static/imgs/icon/icon-finished.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-finished-active.png',
                    inactive: 'static/imgs/icon/icon-finished.png'
                  },
                  value: operations[i].operationName,
                  sort: 8
                })
              }
              // 删除
              if (operations[i].operation == 'delForm') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'delForm',
                  icon: 'static/imgs/icon/icon-delete.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-delete-active.png',
                    inactive: 'static/imgs/icon/icon-delete.png'
                  },
                  value: operations[i].operationName,
                  sort: 9
                })
              }
              // 撤回
              if (operations[i].operation == 'chehui') {
                _this.barList.push({
                  name: operations[i].operationName,
                  operation: 'chehui',
                  icon: 'static/imgs/icon/icon-tuigwms.png',
                  iconTab: {
                    active: 'static/imgs/icon/icon-tuigwms-active.png',
                    inactive: 'static/imgs/icon/icon-tuigwms.png'
                  },
                  value: operations[i].operationName,
                  sort: 10
                })
              }
            }
            // 功能按钮筛选
            if (this.util.isNotEmpty(this.buttonArr)) {
              let newBarList = []
              this.buttonArr.filter((b, index) => this.buttonArr.indexOf(b) === index).forEach((item) => {
                let arr = this.barList.filter(t => t.operation == item)
                if (arr != null && arr.length > 0) {
                  newBarList.push(arr[0])
                }
              })
              this.barList = newBarList
            } else {
              this.barList = []//如果获取到的按钮为空，则置空
            }
            // 大于三个添加更多按钮,第四个按钮为更多操作
            if (_this.barList.length > 3) {
              _this.barList.sort((a, b) => a.sort - b.sort)

              var more = {
                name: '更多',
                operation: 'more',
                icon: 'static/imgs/icon/icon-more.png',
                iconTab: {
                  active: 'static/imgs/icon/icon-more-active.png',
                  inactive: 'static/imgs/icon/icon-more.png',
                },
                value: '更多操作',
              }
              _this.barList.splice(3, 0, more);
            }
          }

        } else {
          console.log("出错了: " + JSON.stringify(data));
        }

      })
    },
    // 已阅提示框
    readGwDialog() {
      this.$dialog.confirm({
        confirmButtonColor: '#1989fa',
        title: '系统提示',
        message: '是否确认已阅?',
      }).then(() => {
        this.readGw()//已阅
      }).catch(() => {
        // on cancel
      });
    },
    // 已阅
    readGw() {
      var _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/approval/saveopinion`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
        },
        data: this.$http.adornData({
          'proInstId': _this.paramObject.proInstId,//发文详情返回的proInstId
          'workItemId': _this.paramObject.workitemId,//
          'actInstId': _this.paramObject.actInstId,//
          'opiniontype': 'jldReview',
          'opinion': '已阅',
          'isApproval': '1',//核稿状态，默认传1
        })
      }).then(({data}) => {
        console.log("------已阅-saveopinion: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.$toast('操作成功')
          this.refreshBtnGroup(true)
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }

      })
    },

    // 退收文人员提示框
    tuiSwry() {
      this.$dialog.confirm({
        confirmButtonColor: '#1989fa',
        title: '系统提示',
        message: '是否退回收文人员?',
      }).then(() => {
        this.jieshuGongWen()
      }).catch(() => {
        // on cancel
      });
    },

    // 结束公文确认弹框
    endProcess() {
      this.$dialog.confirm({
        confirmButtonColor: '#1989fa',
        title: '系统提示',
        message: '确认操作吗?',
      })
              .then(() => {
                this.jieshuGongWen()
              })
              .catch(() => {
                // on cancel
              });
    },
    // 结束公文
    jieshuGongWen() {
      var _this = this
      this.$httploading({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/completeWorkitem`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          data: this.$http.adornData({
            swForm: this.detailObj1.detailObj,//详情
            wfmData: {
              'configId': _this.paramObject.configId,
              'proDirId': _this.paramObject.proDirId,//发文详情返回的proInstId
              'actDefId': _this.paramObject.actDefId,//
              'proInstId': _this.paramObject.proInstId,
              'actInstId': _this.paramObject.actInstId,//
              'workitemId': _this.paramObject.workitemId,
              'nextActivities': _this.endGongWen
            },
          })
        }
      }).then(({data}) => {
        console.log("------结束公文-completeWorkitem-->>: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.$toast('操作成功')
          uni.redirectTo({
            url: '/pages/jgj/send/signList'
          })
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }

      })
    },

    // 获取流转范围
    listNextActivities() {
      console.log("------userInfo: " + JSON.stringify(this.userInfo));
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/listNextActivities?systemKey=` + this.userInfo.systemKey + `&systemFlag=` + this.userInfo.systemFlag),
        method: 'post',
        params: {
          'data': this.$http.adornData({
            wfmData: {
              'configId': _this.paramObject.configId,
              'proDirId': _this.paramObject.proDirId,// 详情返回的proInstId
              'actDefId': _this.paramObject.actDefId,//
              'actInstId': _this.paramObject.actInstId,//
              'workitemId': _this.paramObject.workitemId,
              'wfmInitPageType': 'running'
            }
          })
        }
      }).then(({data}) => {
        console.log("------获取流转范围-listNextActivities===>>>>: " + JSON.stringify(data));
        if (data.code == 200) {
          let nextActDefIds = data.data.nextActDefIds
          let currentActDefId = data.data.actDefId

          if (nextActDefIds) {
            for (var i = 0; i < nextActDefIds.length; i++) {
              // if ("csgwmszz" == nextActDefIds[i].actDefId && currentActDefId.indexOf("scsldsp")>-1) {
              // 	_this.tuiGongWen.push(nextActDefIds[i])
              // }else if("sjzbsgzz" == nextActDefIds[i].actDefId && currentActDefId.indexOf("sjldsh")>-1){
              // 	_this.tuiGongWen.push(nextActDefIds[i])
              // }else if("hqjsr" == nextActDefIds[i].actDefId && currentActDefId.indexOf("scsldhq")>-1){
              // 	_this.tuiGongWen.push(nextActDefIds[i])
              // }
              if (nextActDefIds[i].actDefId == "jzbgszz" || nextActDefIds[i].actDefId == "gljbgszz") {
                _this.tuiGongWen.push(nextActDefIds[i])
              }
              if (nextActDefIds[i].actDefId == "csmszz" || nextActDefIds[i].actDefId == "blbmms" || nextActDefIds[i].actDefId == "csms") {
                _this.tuiCs.push(nextActDefIds[i])
              }

              // 用于分送管理的分送功能
              if (_this.paramObject.actDefId == 'zbss') {
                if (nextActDefIds[i].actType == 'end') {
                  _this.fsActivity.push(nextActDefIds[i])
                }
              } else {
                if (nextActDefIds[i].actDefId == 'gljzlc') {
                  _this.fsActivity.push(nextActDefIds[i])
                }
              }

              if (nextActDefIds[i].actType == 'end') {
                _this.endGongWen.push(nextActDefIds[i])
              }
            }
          }
          console.log("_this.fsActivity: " + JSON.stringify(_this.fsActivity));
          console.log("_this.tuiGongWen: " + JSON.stringify(_this.tuiGongWen));
          console.log("_this.endGongWen: " + JSON.stringify(_this.endGongWen));
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }

      })
    },
    // 退公文秘书
    tuiGwmsConfirm() {
      this.$dialog.confirm({
        title: '系统提示',
        message: '您确定要操作吗?',
      })
              .then(() => {
                if (msType == 'tuichushiMs') {//退处室秘书
                  this.getCsms()
                } else if (msType == 'tgwms') {//退公文秘书
                  this.getJldMsRelate()
                }
              })
              .catch(() => {
                // on cancel
              });
    },
    // 先获取这篇文的秘书
    getJldMsRelate() {
      var _this = this
      this.$http({
        url: this.$http.adornUrl(`/caac/wfm/MhjApplicationController/getJldMsRelate`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          if (JSON.stringify(data.data) != "{}") {
            // let gwms = data.data.filter(t => t.itemCode == this.userInfo.systemKey)
            // if(gwms != null && gwms.length > 0) {
            // 	this.gwSercet = gwms[0]
            // 	this.tuiGwms()
            // }else{
            // 	this.$toast('该领导未配置秘书，需配置！')
            // }
            data.data.forEach((item) => {
              if (this.userInfo.userId == item.ldId) {
                this.gwSercet = item
                return
              }
            })
            this.tuiGwms()
          } else {
            this.$toast('该领导未配置秘书，需配置！')
          }
        }
      })
    },

    // 先获取处室秘书
    getCsms() {
      this.$http({
        url: this.$http.adornUrl(`/caac/oa/authority/sw/chushiMs`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
        })
      }).then(({data}) => {
        if (data.code == 200) {
          if (JSON.stringify(data.data) != "{}") {
            data.data.forEach((item) => {
              this.gwSercetCs = item
            })
            this.tuiCsms()//退处室秘书
          } else {
            this.$toast('该领导未配置秘书，需配置！')
          }
        }
      })
    },
    // 退公文秘书操作
    tuiGwms() {
      if (this.util.isEmpty(this.gwSercet)) {
        this.$toast('该领导未配置秘书，需配置！')
        return
      }
      var _this = this
      _this.tuiGongWen.map(t => t.participants = ('user:' + _this.gwSercet.msId))

      this.$httploading({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/completeWorkitem`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          data: this.$http.adornData({
            swForm: this.detailObj1.detailObj,//详情
            wfmData: {
              'configId': _this.paramObject.configId,
              'proDirId': _this.paramObject.proDirId,//发文详情返回的proInstId
              'actDefId': _this.paramObject.actDefId,//
              'proInstId': _this.paramObject.proInstId,
              'actInstId': _this.paramObject.actInstId,//
              'workitemId': _this.paramObject.workitemId,
              'nextActivities': _this.tuiGongWen
            },
          })
        }
      }).then(({data}) => {
        // console.log("------退公文秘书-completeWorkitem-->>: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.$toast("操作成功")
          // 发送通知
          let messageUserIds = this.gwSercet.msId;
          let linkUrl = this.configUtil.baseUrl + this.configUtil.basePath + "/#/pages/jgj/receive/index?proInstId=" + this.paramObject.proInstId + "&from=db";
          this.lx.sendMessage(this.cache.get("appType"), messageUserIds,
              this.detailObj1.detailObj.title, "收文", linkUrl);
          uni.redirectTo({
            url: '/pages/jgj/send/signList'
          })
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }
      })
    },
    // 退处室秘书操作
    tuiCsms() {
      if (this.util.isEmpty(this.gwSercetCs)) {
        this.$toast('该领导未配置秘书，需配置！')
        return
      }
      var _this = this
      _this.tuiCs.map(t => t.participants = ('user:' + _this.gwSercetCs.userId))
      this.$httploading({
        url: this.$http.adornUrl(`/caac/wfm/ApplicationController/completeWorkitem`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          data: this.$http.adornData({
            swForm: this.detailObj1.detailObj,//详情
            wfmData: {
              'configId': _this.paramObject.configId,
              'proDirId': _this.paramObject.proDirId,//发文详情返回的proInstId
              'actDefId': _this.paramObject.actDefId,//
              'proInstId': _this.paramObject.proInstId,
              'actInstId': _this.paramObject.actInstId,//
              'workitemId': _this.paramObject.workitemId,
              'nextActivities': _this.tuiCs
            },
          })
        }
      }).then(({data}) => {
        // console.log("------退公文秘书-completeWorkitem-->>: " + JSON.stringify(data));
        if (data.code == 200) {
          _this.$toast("操作成功")
          // 发送通知
          let messageUserIds = this.gwSercetCs.userId;
          let linkUrl = this.configUtil.baseUrl + this.configUtil.basePath + "/#/pages/jgj/receive/index?proInstId=" + this.paramObject.proInstId + "&from=db";
          this.lx.sendMessage(this.cache.get("appType"), messageUserIds,
              this.detailObj1.detailObj.title, "收文", linkUrl);
          uni.redirectTo({
            url: '/pages/admin/send/signList'
          })
        } else {
          _this.$toast(data.message + ' code:' + data.code)
        }
      })
    },

    // 删除公文
    deleteDoc() {
      this.$dialog.confirm({
        title: '系统提示',
        message: '确定要删除吗?',
      }).then(() => {
        // on confirm
        this.$http({
          url: this.$http.adornUrl(`/caac/oa/authority/sw`),
          method: 'delete',
          params: this.$http.adornParams({
            'systemKey': this.userInfo.systemKey,
            'systemFlag': this.userInfo.systemFlag,
            'swId': this.swId
          })
        }).then(({data}) => {
          if (data.code == 200) {
            this.$toast('删除成功')
          } else {
            this.$toast(data.message + ' code:' + data.code)
          }
        })

      })
              .catch(() => {
                // on cancel
              });
    },
    // 撤回确认提示框
    chehuiConfirm() {
      this.$dialog.confirm({
        title: '系统提示',
        message: '您确定要操作吗?',
      }).then(() => {
        this.chehui()
      }).catch(() => {
        // on cancel
      });
    },
    chehui(){
      this.$httploading({
        url: this.$http.adornUrl(`/caac/oa/component/workflow/workflowController/swRemoveprocess`),
        method: 'post',
        params: {
          'systemKey': this.userInfo.systemKey,//固定值
          'systemFlag': this.userInfo.systemFlag,//固定值
          'data':this.$http.adornData({
            'configId': this.paramObject.configId,
            'proDirId': this.paramObject.proDirId,//发文详情返回的proInstId
            'actDefId': this.paramObject.actDefId,//
            'proInstId': this.paramObject.proInstId,
            'actInstId': this.paramObject.actInstId,//
            'removeWorkitemIds': this.paramObject.workitemId,
            'subProInstId': this.detailObj1.detailObj.subProInstId
          })
        },
      }).then(({data}) => {
        if (data.code == 200) {
          this.$toast(data.data.message)
          uni.redirectTo({
            url: '/pages/admin/receive/doList'
          })
        } else {
          this.$toast("撤回失败，code："+data.code)
        }
      })
    }


  },
};
</script>

<style scoped>

</style>
